<template>
  <div v-if="isVisible" class="modal-backdrop">
    <div class="modal-content">
      <h3 :class="messageTypeClass">{{ title }}</h3>
      <p class="message-text">{{ message }}</p>
      <div class="modal-actions">
        <button @click="closeModal" class="ok-button">确定</button>
      </div>
    </div>
  </div>
</template>

<script setup>
import { defineProps, defineEmits, computed } from 'vue';

const props = defineProps({
  isVisible: {
    type: Boolean,
    default: false
  },
  title: {
    type: String,
    required: true
  },
  message: {
    type: String,
    required: true
  },
  type: {
    type: String,
    default: 'info' // 'info', 'success', 'error'
  }
});

const emit = defineEmits(['close']);

const messageTypeClass = computed(() => {
  return {
    'title-info': props.type === 'info',
    'title-success': props.type === 'success',
    'title-error': props.type === 'error'
  };
});

const closeModal = () => {
  emit('close');
};
</script>

<style scoped>
.modal-backdrop {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background-color: rgba(0, 0, 0, 0.6);
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: 1001; /* Higher than RefundConfirmationModal */
}

.modal-content {
  background-color: #fff;
  padding: 2rem;
  border-radius: 10px;
  box-shadow: 0 5px 15px rgba(0, 0, 0, 0.3);
  width: 90%;
  max-width: 400px;
  text-align: center;
  animation: fadeIn 0.3s ease-out;
}

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(-20px); }
  to { opacity: 1; transform: translateY(0); }
}

h3 {
  margin-bottom: 1.5rem;
  font-size: 1.5rem;
}

.title-info {
  color: #007bff;
}

.title-success {
  color: #28a745;
}

.title-error {
  color: #dc3545;
}

.message-text {
  white-space: pre-wrap; /* Preserves line breaks */
  text-align: center;
  margin-bottom: 2rem;
  color: #555;
  line-height: 1.6;
  font-size: 1.1rem;
}

.modal-actions {
  display: flex;
  justify-content: center;
}

.ok-button {
  padding: 0.8rem 1.8rem;
  background-color: #007bff;
  color: white;
  border: none;
  border-radius: 5px;
  cursor: pointer;
  font-size: 1.1rem;
  transition: background-color 0.3s ease;
}

.ok-button:hover {
  background-color: #0056b3;
}
</style>
